#include "tray-manager.h"

using namespace Core;

TrayManager::TrayManager(QObject *parent) : QObject(parent)
{
    setIcon(Standard);
    createMenu();
    show();
}

void Core::TrayManager::createMenu()
{
    trayMenu.addAction(QIcon(":/icons/menu/exit"), "Exit", this, SLOT(exitTriggered()));

    trayIcon.setContextMenu(&trayMenu);
}

void TrayManager::show()
{
    trayIcon.show();
}

void TrayManager::hide()
{
    trayIcon.hide();
}

void TrayManager::setIcon(TrayManager::Icon icon)
{
    switch(icon)
    {
    case Updating:
        trayIcon.setIcon(QIcon(":/icons/update"));
        break;
    case Standard:
    default:
        trayIcon.setIcon(QIcon(":/icons/main-icon"));
        break;
    }
}

void TrayManager::showInfoMessage(const QString &message)
{
    trayIcon.showMessage("Information - LearnEnglish", message);
}

void Core::TrayManager::showAlertMessage(const QString &message)
{
    trayIcon.showMessage("Alert - LearnEnglish", message, QSystemTrayIcon::Warning);
}

void TrayManager::showErrorMessage(const QString &message)
{
    trayIcon.showMessage("Error - LearnEnglish", message, QSystemTrayIcon::Critical);
}

void Core::TrayManager::exitTriggered()
{
    emit exit();
}
